package org.wat.wcy.isi.mmazur.bp.io.model;

import java.io.IOException;
import java.io.RandomAccessFile;

import org.wat.wcy.isi.mmazur.bp.io.BinaryObject;

public class GraphicsInfo extends BinaryObject {
	
	private int x, y, width, height;

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public GraphicsInfo(int x, int y, int width, int height) {
		super();
		this.x = x;
		this.y = y;
		this.width = width;
		this.height = height;
	}

	public boolean contains(GraphicsInfo r) {
		if (r != null) {
			boolean test = this.x <= r.x && this.y <= r.y;
			test &= (this.x + this.width) >= (r.x + r.width);
			test &= (this.y + this.height) >= (r.y + r.height);
			return test;
		}
		return false;
	}
	
	public String toString() {
		return String.format("Rectangle [%d, %d, %d, %d]", x, y, width, height);
	}

	@Override
	public void read(RandomAccessFile raf) {
		try {
			x = raf.readInt();
			y = raf.readInt();
			width = raf.readInt();
			height = raf.readInt();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static int sizeOf() {
		return (int)(Integer.SIZE / 8) * 4;
	}

	@Override
	public void write(RandomAccessFile raf) {
		try {
			raf.writeInt(x);
			raf.writeInt(y);
			raf.writeInt(width);
			raf.writeInt(height);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
